<template>
	<view class="page_login">
		
		<image class="logo" src="../../static/img/login.png" mode="widthFix"></image>
	
		<view class="login_text">
			创你所想
		</view>
		
		<image class="login_img" src="../../static/img/img_1.png" mode="widthFix"></image>
		
		<!-- <button class="login_btn" @click="gotoNext">
			手机号快捷登录
		</button> -->
		<button class="login_btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">手机号快捷登录</button>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				fromid:'',
				liveId:''
			}
		},
		onLoad(opt) {
			this.fromid = uni.getStorageSync('fromid');
			if(opt.liveId){
				console.log('liveId-----', opt.liveId)
				this.liveId = opt.liveId
			}
		},
		methods: {
			getPhoneNumber(res){
				const that = this
				console.log('获取code---',res.detail.code)
				if (res.detail.errMsg == "getPhoneNumber:ok") {
					uni.request({
						url: `https://www.shenmaio.com/api/wechat_phone?from=miniprogram&bid=888&code=${res.detail.code}`,
						success: (ret) => {
							console.log('接口wechat_phone------',ret)
							if(!ret.data.status) {
								uni.showToast({ title: ret.data.message, icon: "error" })
								return;
							}
							uni.request({
								url: `https://www.shenmaio.com/api/aigc_login?phone=${ret.data.data}&login_type=wechat_login&fromid=${that.fromid}&from=miniprogram`,
								//url: `https://www.shenmaio.com/api/aigc_login?phone=${13795219626}&login_type=wechat_login&from=miniprogram`,
								success: (resa) => {
									console.log('登录aigc_login---',resa);
									if(!resa.data.status) {
										uni.showToast({ title: resa.data.message, icon: "error" })
										return;
									}
									uni.authorize({
									    scope: 'scope.record',
									    success() {
											console.log('同意获取麦克风权限---');
									        uni.setStorageSync("userInfo", JSON.stringify(resa.data.data));
									        uni.setStorageSync("token", resa.data.data.token);
									        uni.setStorageSync("isLogin", true);
									        uni.setStorageSync("userId", resa.data.data.user_id);
									        uni.reLaunch({
									        	url: "/pages/index/index?liveId=" + that.liveId
									        })
									    },
										fail(){
											console.log('拒绝获取麦克风权限---');
										}
										
									})
									
								}
							})
						}
					})
				}else{
					uni.showToast({
						title: '授权已取消',
						icon: 'error',
						mask: true,
					});
				}
			},
			gotoNext(){
				// wx.login({
				//   success (res) {
				// 	  console.log('code----', res.code)
				// 	if (res.code) {
				// 	  //发起网络请求
				// 	  wx.request({
				// 		url: 'https://example.com/onLogin',
				// 		data: {
				// 		  code: res.code
				// 		}
				// 	  })
				// 	} else {
				// 	  console.log('登录失败！' + res.errMsg)
				// 	}
				//   }
				// })
				uni.redirectTo({
					url: '/pages/index/index?liveId=' + this.liveId
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
.page_login{
	width: 100%;
	height: 100vh;
	background: linear-gradient(180deg, #050513 0%, #000000 100%);
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-direction: column;
	padding:10vh 0 8vh;
	box-sizing: border-box;
	.logo{
		width: 166rpx;
	}
	.login_text{
		color: rgba(255, 255, 255, 0.5638);
		font-size: 28rpx;
		line-height: 40rpx;
		padding:30rpx 0 100rpx;
	}
	.login_img{
		width: 586rpx;
		margin-bottom: auto;
	}
	.login_btn{
		display: block;
		width: 666rpx;
		height: 80rpx;
		line-height: 80rpx;
		border-radius: 80rpx;
		opacity: 1;
		background: #F2B901;
		font-size: 30rpx;
		font-weight: bold;
	}
}
</style>
